package cn.mumzone.pos.ui.adapter;

import android.content.Context;
import android.view.View;

import cn.mumzone.basic.adapter.rv.CommonAdapter;
import cn.mumzone.basic.adapter.rv.ViewHolder;
import cn.mumzone.pos.R;
import cn.mumzone.pos.model.SimpleEntity;


/**
 * Created by qiuzhenhuan on 2019/3/29.
 */

public class ADA_SimpleList extends CommonAdapter<SimpleEntity> {

    public ADA_SimpleList(Context context) {
        super(context);
    }

    @Override
    protected int itemLayoutId() {
        return R.layout.item_simple_list;
    }

    @Override
    protected void convert(ViewHolder holder, final SimpleEntity s, int position) {
        holder.setText(R.id.tv_name, s.getName());
        holder.setVisible(R.id.view_line, position != getItemCount() - 1);

        holder.setOnClickListener(R.id.tv_name, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onItemClickListener != null) {
                    onItemClickListener.onItemClicked(v, s);
                }
            }
        });
    }

    private OnItemClickListener onItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {

        void onItemClicked(View view, SimpleEntity name);
    }
}
